﻿/*
 * OperationContext
 * 
 * Author: snowdreamist
 * Date: 2011/12/14
 * 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BitTorrentSharp.KRPC
{
    public class OperationContext : IDisposable
    {
        #region thread static
        [ThreadStatic]
        private static OperationContext _current;
        /// <summary>
        /// Current OperationContext
        /// </summary>
        public static OperationContext Current
        {
            get
            {
                return _current;
            }
            private set
            {
                _current = value;
            }
        }

        #endregion

        public OperationContext()
        {
            if (OperationContext.Current != null)
                throw new InvalidOperationException("OperationContext.Current is not null");
            OperationContext.Current = this;
        }
        /// <summary>
        /// Dispose
        /// </summary>
        public void Dispose()
        {
            OperationContext.Current = null;
        }
    }
}
